//
//  HomeController.m
//  Kugou-OC
//
//  Created by BH on 16/1/22.
//  Copyright © 2016年 Sunny. All rights reserved.
//

#import "HomeController.h"
#import "GlobalDefine.h"
#import "CustomNavView.h"
#import "ListenView.h"
#import "LookView.h"
#import "SingView.h"
#import "LocalMusicController.h"
#import "MusicLibraryController.h"
#import <SDAutoLayout/UIView+SDAutoLayout.h>

@interface HomeController ()<CustomNavViewDelegate>
//自定义导航栏
@property(nonatomic,strong)CustomNavView *navView;
//听view
@property(nonatomic,strong)ListenView *listenView;
//看view
@property(nonatomic,strong)LookView *lookView;
//唱view
@property(nonatomic,strong)SingView *singView;

@end

@implementation HomeController
-(instancetype)init
{
    self = [super init];
    if (self) {        
        
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

-(void)viewDidLoad
{
    [super viewDidLoad];
    
    //设置背景
    UIImageView *bgImgV = [[UIImageView alloc] init];
    bgImgV.image = IMAGE(@"home_background");
    [self.view sd_addSubviews:@[bgImgV]];
    
    bgImgV.sd_layout.leftEqualToView(self.view).topSpaceToView(self.view,0).rightEqualToView(self.view).bottomSpaceToView(self.view,0);
    
    //添加导航栏
    self.navView = [[CustomNavView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)];
    self.navView.delegate = self;
    [self.view addSubview:self.navView];
    
    //添加subview
    [self addSubviews];
}

/**
 *  添加subview
 */
-(void)addSubviews
{
    __block HomeController *selfBlock = self;
    
    _listenView = [[ListenView alloc] init];
    _listenView.hidden = NO;
    [self.view addSubview:_listenView];
    _listenView.sd_layout.leftEqualToView(self.view).topSpaceToView(self.navView,10).rightEqualToView(self.view).bottomSpaceToView(self.view,90);
    
    _lookView = [[LookView alloc] init];
    _lookView.hidden = YES;
    [self.view addSubview:_lookView];
    _lookView.sd_layout.leftEqualToView(self.view).topSpaceToView(self.navView,10).rightEqualToView(self.view).bottomSpaceToView(self.view,90);
    
    _singView = [[SingView alloc] init];
    _singView.hidden = YES;
    [self.view addSubview:_singView];
    _singView.sd_layout.leftEqualToView(self.view).topSpaceToView(self.navView,10).rightEqualToView(self.view).bottomSpaceToView(self.view,90);
    
    //push LocalMusicController
    _listenView.showViewWithLocalMusic = ^(NSArray *array,NSInteger index){
        LocalMusicController *localMVC = ALLOC(LocalMusicController);
        localMVC.localList = array;
        localMVC.playIndex = index;
        [selfBlock.navigationController pushViewController:localMVC animated:YES];
    };
    
    //push MusicLibraryController
    _listenView.showMusicLibrary = ^(){
        [selfBlock.navigationController pushViewController:ALLOC(MusicLibraryController) animated:YES];
    };
}

#pragma mark - CustomNavViewDelegate
-(void)navBtnClick:(NSInteger)tag{
    NSInteger btnTag = tag-100;
    
    if (btnTag == 0) {
        _listenView.hidden = NO;
        _lookView.hidden = YES;
        _singView.hidden = YES;
    }else if (btnTag == 1){
        _listenView.hidden = YES;
        _lookView.hidden = NO;
        _singView.hidden = YES;
    }else{
        _singView.hidden = NO;
        _listenView.hidden = YES;
        _lookView.hidden = YES;
    }
}

@end
